package cc.co.cutenimy.nimyexplore.ui.grid;

import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

/**
 * Help to create widget with {@link GridLayout} and GridData
 * 
 * 
 * @author 234aini@gmail.com
 * 
 */
public class GridWidget {

	private Composite composite;
	private static GridWidget _this;
	private static GridLayout layout;

	public static TreeViewer createTreeViewer(final Composite parent) {
		GridLayoutFactory.fillDefaults().numColumns(1).applyTo(parent);
		TreeViewer viewer = new TreeViewer(parent);
		// viewer.getTree().setHeaderVisible(true);
		viewer.getTree().setLinesVisible(true);
		GridDataFactory.fillDefaults().grab(true, true)
				.applyTo(viewer.getControl());
		return viewer;
	}

	public static GridWidget forIt(Composite composite) {
		_this = new GridWidget();
		_this.composite = composite;
		layout = new GridLayout();
		return _this;
	}

	public GridWidget num(int i) {
		Assert.isLegal(i > 0, "Columns must be more than zero");
		layout.numColumns = i;
		return _this;
	}

	public void apply() {
		_this.composite.setLayout(layout);
	}

	public static void newComposite() {
		// TODO Auto-generated method stub
		
	}
}
